home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 July / macformat-026.iso / mac / Shareware City / Science / µSim 1.0 folder / source / DragManSim.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-06  |  7.2 KB  |  260 lines  |  [TEXT/MMCC]

  1. #ifndef __DRAG__
  2. #include <Drag.h>
  3. #endif
  4.  
  5. #include    "Assembler.h"
  6. #include    "CursorBalloon.h"
  7. #include    "DragManSim.h"
  8. #include    "Globals.h"
  9. #include    "myMemory.h"
  10.  
  11. typedef struct myglobptr {
  12.     Boolean    canAcceptDrag;
  13.     Boolean    inContent;
  14.     } GlobalsData, *GlobalsPtr;
  15.  
  16. GlobalsData        gmyGlobals;
  17.  
  18. static pascal OSErr MyTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
  19.                         void *handlerRefCon, DragReference theDrag);
  20. static Boolean IsMyTypeAvailable(WindowPtr theWindow, DragReference theDrag);
  21. static pascal OSErr MyReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
  22.                         DragReference theDrag);
  23.  
  24.  
  25. /*
  26. OSErr MyInitDragManager(void)
  27. {
  28. OSErr    err;
  29.  
  30. err = InstallTrackingHandler(MyDefaultTrackingHandler, 0L, &myGlobals);
  31. if (err == noErr)
  32.     err = InstallReceiveHandler(MyDefaultReceiveHandler, 0L, &myGlobals);
  33.  
  34. return err;
  35. }
  36. */
  37.  
  38. OSErr MyInstallHWindow(WindowPtr theWindow)
  39. {
  40. OSErr       err;
  41.  
  42. ((FabWindowPtr)theWindow)->trackUPP = NewDragTrackingHandlerProc(MyTrackingHandler);
  43. ((FabWindowPtr)theWindow)->recUPP = NewDragReceiveHandlerProc(MyReceiveHandler);
  44.  
  45. if ((err = InstallTrackingHandler(((FabWindowPtr)theWindow)->trackUPP, theWindow, &gmyGlobals)) == noErr) {
  46.     err = InstallReceiveHandler(((FabWindowPtr)theWindow)->recUPP, theWindow, &gmyGlobals);
  47.     if (err)
  48.         RemoveTrackingHandler(((FabWindowPtr)theWindow)->trackUPP, theWindow);
  49.     }
  50. else
  51.     DebugStr("\pMyInstallHWindow error on InstallTrackingHandler");
  52.  
  53. return err;
  54. }
  55.  
  56. void MyRemoveHWindow(WindowPtr theWindow)
  57. {
  58. (void) RemoveTrackingHandler(((FabWindowPtr)theWindow)->trackUPP, theWindow);
  59. (void) RemoveReceiveHandler(((FabWindowPtr)theWindow)->recUPP, theWindow);
  60. if (((FabWindowPtr)theWindow)->trackUPP) {
  61.     DisposeRoutineDescriptor(((FabWindowPtr)theWindow)->trackUPP);
  62.     ((FabWindowPtr)theWindow)->trackUPP = nil;
  63.     }
  64. if (((FabWindowPtr)theWindow)->recUPP) {
  65.     DisposeRoutineDescriptor(((FabWindowPtr)theWindow)->recUPP);
  66.     ((FabWindowPtr)theWindow)->recUPP = nil;
  67.     }
  68. }
  69.  
  70. pascal OSErr MyTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
  71.                         void *handlerRefCon, DragReference theDrag)
  72. {
  73. Rect    tempRect = {0, 0, 0, 0};
  74. GlobalsPtr        myGlobals = (GlobalsPtr) handlerRefCon;
  75. Point            mouse, localMouse;
  76. void (*theProc)(WindowPtr, RectPtr);
  77. DragAttributes    attributes;
  78. RgnHandle        hiliteRgn;
  79. OSErr    err;
  80.  
  81. if ((err = GetDragAttributes(theDrag, &attributes)) == noErr) {
  82.     switch(theMessage) {
  83. //        case dragTrackingEnterHandler:
  84. //            break;
  85.         case dragTrackingEnterWindow:
  86.             myGlobals->canAcceptDrag = IsMyTypeAvailable(theWindow, theDrag);
  87.             myGlobals->inContent = false;
  88.             break;
  89.         case dragTrackingInWindow:
  90.             if (myGlobals->canAcceptDrag) {
  91.                 if ((err = GetDragMouse(theDrag, &mouse, 0L)) == noErr) {
  92.                     localMouse = mouse;
  93.                     GlobalToLocal(&localMouse);
  94.                     if (attributes & dragHasLeftSenderWindow) {
  95.                         theProc = ((FabWindowPtr)theWindow)->getDragHiliteRectProc;
  96.                         if (theProc)
  97.                             theProc(theWindow, &tempRect);
  98.                         if (PtInRect(localMouse, &tempRect)) {
  99.                             if (myGlobals->inContent == false) {
  100.                                 hiliteRgn = NewRgn();
  101.                                 if (hiliteRgn) {
  102.                                     //InsetRect(&tempRect, 1, 1);
  103.                                     RectRgn(hiliteRgn, &tempRect);
  104.                                     (void) ShowDragHilite(theDrag, hiliteRgn, true);
  105.                                     DisposeRgn(hiliteRgn);
  106.                                     }
  107.                                 myGlobals->inContent = true;
  108.                                 }
  109.                             }
  110.                         else {
  111.                             if (myGlobals->inContent) {
  112.                                 (void) HideDragHilite(theDrag);
  113.                                 myGlobals->inContent = false;
  114.                                 }
  115.                             }
  116.                         }
  117.                     }
  118.     //            MyTrackItemUnderMouse(localMouse, theWindow);
  119.                 }
  120.             break;
  121.         case dragTrackingLeaveWindow:
  122.             if (myGlobals->canAcceptDrag && myGlobals->inContent) {
  123.                 (void) HideDragHilite(theDrag);
  124.                 }
  125.             myGlobals->canAcceptDrag = false;
  126.             break;
  127. //        case dragTrackingLeaveHandler:
  128. //            break;
  129.         }
  130.     }
  131. return err;
  132. }
  133.  
  134. Boolean IsMyTypeAvailable(WindowPtr theWindow, DragReference theDrag)
  135. {
  136. //HVolumeParam    mypb;
  137. FSSpec            copySpec;
  138. HFSFlavor        *theData;
  139. //AliasHandle        tempFolder;
  140. Size            dataSize;
  141. //FlavorFlags        theFlags;
  142. ItemReference    theItem;
  143. unsigned short    items, index;
  144. OSErr            err;
  145. Boolean            targetFolder, isAnAlias;
  146. Boolean            retVal = true;
  147.  
  148.  
  149. if ((err = CountDragItems(theDrag, &items)) == noErr) {
  150.     for (index = 1; (index <= items) && retVal; index++) {
  151.         if ((err = GetDragItemReferenceNumber(theDrag, index, &theItem)) == noErr) {
  152. //            if ((err = GetFlavorFlags(theDrag, theItem, flavorTypeHFS, &theFlags)) == noErr) {
  153.                 if ((err = GetFlavorDataSize(theDrag, theItem, flavorTypeHFS, &dataSize)) == noErr) {
  154.                     theData = (HFSFlavor *)NewPtr(dataSize);
  155.                     if (theData) {
  156.                         if ((err = GetFlavorData(theDrag, theItem, flavorTypeHFS, theData, &dataSize, 0L)) == noErr) {
  157.                             switch (theData->fileType) {
  158.                                 case kFTY_REG:
  159.                                     retVal = theWindow == gWPtr_Registers;
  160.                                     break;
  161.                                 case kFTY_RAM:
  162.                                 case 'TEXT':
  163.                                     retVal = theWindow == gWPtr_Disasm || theWindow == gWPtr_Dump;
  164.                                     break;
  165.                                 default:
  166.                                     retVal = false;
  167.                                 }
  168.                             if (retVal) {
  169.                                 copySpec = theData->fileSpec;
  170.                                 if (err = ResolveAliasFile(©Spec, true, &targetFolder, &isAnAlias))
  171.                                     retVal = false;
  172.                                 }
  173.                             }
  174.                         else
  175.                             retVal = false;
  176.                         DisposePtr((Ptr)theData);
  177.                         }
  178.                     else
  179.                         retVal = false;
  180.                     }
  181.                 else
  182.                     retVal = false;
  183. //                }
  184. //            else
  185. //                retVal = false;
  186.             }
  187.         else
  188.             retVal = false;
  189.         }
  190.     }
  191. else
  192.     retVal = false;
  193. return retVal;
  194. }
  195.  
  196. pascal OSErr MyReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
  197.                         DragReference theDrag)
  198. {
  199. GlobalsPtr        myGlobals = (GlobalsPtr) handlerRefCon;
  200. //HVolumeParam    mypb;
  201. FSSpec            copySpec;
  202. HFSFlavor        *theData;
  203. //AliasHandle        tempFolder;
  204. //Point            mouse;
  205. ItemReference    theItem;
  206. //FlavorFlags        theFlags;
  207. Size            dataSize;
  208. unsigned short    items, index;
  209. OSErr            err = noErr;
  210. Boolean            targetFolder, isAnAlias;
  211.  
  212. //if ((err = GetDragMouse(theDrag, &mouse, 0L)) == noErr) {
  213. if (myGlobals->canAcceptDrag && myGlobals->inContent) {
  214.     if ((err = CountDragItems(theDrag, &items)) == noErr) {
  215.         for (index = 1; (index <= items) && (err == noErr); index++) {
  216.             if ((err = GetDragItemReferenceNumber(theDrag, index, &theItem)) == noErr) {
  217. //                if ((err = GetFlavorFlags(theDrag, theItem, flavorTypeHFS, &theFlags)) == noErr) {
  218.                     if ((err = GetFlavorDataSize(theDrag, theItem, flavorTypeHFS, &dataSize)) == noErr) {
  219.                         theData = (HFSFlavor *)NewPtr(dataSize);
  220.                         if (theData) {
  221.                             if ((err = GetFlavorData(theDrag, theItem, flavorTypeHFS, theData, &dataSize, 0L)) == noErr) {
  222.                                 copySpec = theData->fileSpec;
  223.                                 if ((err = ResolveAliasFile(©Spec, true, &targetFolder, &isAnAlias)) == noErr) {
  224.                                     switch (theData->fileType) {
  225.                                         case kFTY_REG:
  226.                                             err = OpenProcessorState(©Spec);
  227.                                             UnloadSeg(OpenProcessorState);
  228.                                             break;
  229.                                         case kFTY_RAM:
  230.                                             err = myOpenFile(©Spec, gMMemory, kSIZE_RAM);
  231.                                             UnloadSeg(myOpenFile);
  232.                                             break;
  233.                                         case 'TEXT':
  234.                                             err = myAsmFile(©Spec);
  235.                                             UnloadSeg(myAsmFile);
  236.                                             break;
  237.                                         default:
  238.                                             err = dragNotAcceptedErr;
  239.                                         }
  240.                                     }
  241.                                 }
  242.                             DisposePtr((Ptr)theData);
  243.                             }
  244.                         else
  245.                             err = dragNotAcceptedErr;
  246.                         }
  247. //                    }
  248.                 }
  249.             }
  250.         }
  251.     }
  252. else
  253.     err = dragNotAcceptedErr;
  254.  
  255. if (err)
  256.     err = dragNotAcceptedErr;
  257. return err;
  258. }
  259.  
  260.